"""
消息相关数据模型
"""

from typing import Optional, List
from pydantic import BaseModel, Field
from models.common import BaseEntity

class MessageBase(BaseModel):
    """消息基础模型"""
    title: str = Field(..., max_length=200, description="消息标题")
    content: str = Field(..., description="消息内容")
    message_type: str = Field(..., max_length=50, description="消息类型")
    priority: str = Field(default="normal", description="优先级")
    sender_id: Optional[int] = Field(None, description="发送者ID")
    receiver_id: Optional[int] = Field(None, description="接收者ID")

class MessageCreate(MessageBase):
    """创建消息模型"""
    pass

class Message(MessageBase, BaseEntity):
    """消息模型"""
    is_read: bool = Field(default=False, description="是否已读")
    read_at: Optional[str] = Field(None, description="阅读时间")

class MessageRead(BaseModel):
    """消息已读模型"""
    message_id: int = Field(..., description="消息ID")
    user_id: int = Field(..., description="用户ID")
    read_at: str = Field(..., description="阅读时间")
    
    class Config:
        from_attributes = True

class MessageList(BaseModel):
    """消息列表响应模型"""
    messages: List[Message]
    unread_count: int = Field(..., description="未读消息数量")
    total_count: int = Field(..., description="总消息数量")